<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
<%@ page import="java.util.List" %>
<%@ page import="user.Grade" %><%--
  Created by IntelliJ IDEA.
  User: 长风无言
  Date: 2020/11/13
  Time: 15:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.min.css">
</head>
<style>
    .a{
        width: 960px;
        height: 660px;
        position: relative;
        top:25%;
        left: 20.5%;
    }
    .blue{
        background: #D9EDF7;
    }
    .yellow{
        background: #FCF8E3;
    }
    .b{
        position: absolute;
        left: 300px;
    }
</style>
<body>
<script>
    var flag = true;
</script>
<div class=a>
    <div style="padding: 10px;">
        <button id="Tostudent" class="btn btn-primary">学生管理</button>
        <button id="add" class="btn btn-primary" data-toggle="modal" data-target="#myModal1">增加</button>
        <button id="delete" class="btn btn-primary">删除</button>
        <button id="find" class="btn btn-primary">查询</button> <input type="text" class="img-rounded" width="44%" id="a" placeholder="按序号查询"> <input type="text" class="img-rounded" width="44%" id="b" placeholder="按姓名查询">

    </div>
    <table class="table table-bordered" id="table1">
        <thead>
        <tr>
            <th></th>
            <th>序号</th>
            <th>班级</th>
            <th>年级</th>
            <th>班主任</th>
            <th>口号</th>
            <th>总人数</th>
        </tr>
        </thead>
        <tbody>
        <%
            int numid=0;
            List<Grade> grades = ((List<Grade>)session.getAttribute("list"));
            pageContext.setAttribute("grades",grades);
            pageContext.setAttribute("numid",numid);
        %>

        <c:forEach var="grades1" items="${grades}">

            <tr class=${((flag=!flag)?"info":"warning")}>
                <td ><input type="checkbox" name="test" id="<c:out value="${numid=numid+1}"></c:out>"></td>
                <td><c:out value="${grades1.getNum()}"></c:out></td>
                <td ><input class="${(flag?"blue":"yellow")}" type="text" style="border:none;" placeholder="<c:out value="${grades1.getName()}"></c:out>"> </td>
                <td ><input class="${(flag?"blue":"yellow")}" type="text" style="border:none;" placeholder="<c:out value="${grades1.getYear()}"></c:out>"> </td>
                <td ><input class="${(flag?"blue":"yellow")}" type="text" style="border:none;" placeholder="<c:out value="${grades1.getTeacher()}"></c:out>"> </td>
                <td ><input class="${(flag?"blue":"yellow")}" type="text" style="border:none;" placeholder="<c:out value="${grades1.getSlogan()}"></c:out>"> </td>
                <td ><input class="${(flag?"blue":"yellow")}" type="text" style="border:none;" placeholder="<c:out value="${grades1.getPeopleNum()}"></c:out>"> </td>

            </tr>
        </c:forEach>
        </tbody>

    </table>
    <div style="padding: 10px;" class="b">

        <%
            int count = (int)session.getAttribute("count");
            int pagenum = (int) session.getAttribute("pagenum");
            int i= (int)session.getAttribute("start");
            int center=i+1;
            int x=0;
            if(i==1){
                x=1;
            }else if((pagenum-1)>i&&i>1){
                x=2;
            }else if(i>=(pagenum-1)){
                x=i-pagenum+4;
            }
            pageContext.setAttribute("count",count);
            pageContext.setAttribute("pagenum",pagenum);
            pageContext.setAttribute("center",center);
            pageContext.setAttribute("x",x);
            pageContext.setAttribute("i",i);
        %>
        <div style="text-align: center;padding-bottom: 20px" >
            一共<c:out value="${count}"></c:out>条数据
        </div>
        <button id="previous" class="btn btn-primary">上一页</button>
        <%
            for (int z = 0; z<(Math.min(pagenum, 5)); z++,center++){
                if(center-x<=pagenum+1){
                    pageContext.setAttribute("center",center);

//                    System.out.println(pagenum+";"+i);
        %>
        <button class="btn btn-primary" name="page"><c:out value="${center-x}"></c:out></button>
        <%
                }
            }
        %>
        <button id="next" class="btn btn-primary">下一页</button>

    </div>
</div>

<!-- <button class="btn btn-warning" data-toggle="modal" data-target="#myModal">弹框</button> -->
<div class="modal" id="myModal1" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">请输入增添人员信息</h4>
            </div>
            <div style="text-align: center">
                <form action="addgrade" method="post">
                    <p>序&nbsp;&nbsp;&nbsp;&nbsp;号：<input type="text"name="num"></p>
                    <p>班&nbsp;&nbsp;&nbsp;&nbsp;级：<input type="text"name="name"></p>
                    <p>年&nbsp;&nbsp;&nbsp;&nbsp;级：<input type="text"name="year"></p>
                    <p>班主任：<input type="text"name="teacher"></p>
                    <p>口&nbsp;&nbsp;&nbsp;&nbsp;号：<input type="text"name="slogan"></p>
                    <p>总人数：<input type="text"name="peoplenum"></p>
                    <div class="form-group" style="text-align: center">
                        <input type="submit" value="确定" class="btn btn-info" id="sure1"></input>
                        <input type="reset" value="取消" class="btn btn-default" data-dismiss="modal"> </input>
                    </div>
                </form>
            </div>
            <div class="modal-footer">

            </div>
        </div>
    </div>
</div>

<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>

<script>
    $("#Tostudent").click(function(){
        location.href=`managerinit`;
    });

    $("#delete").click(function(){
        $("input[name='test']:checked").each(function() {
            n = $(this).parents("tr").index();
            num = $("#table1").find("tr:eq(" + (n + 1) + ")").find("td:eq(1)").text();
        });
        location.href=`deleteGrade?num=` + num;
    });

    $('#find').click(function() {
        var a=$('#a').val();
        var b=$('#b').val();
        if(""!=a){
            location.href=`findgrade?num=`+a;
        }
        else if(""!=b){
            location.href=`findgrade?name=`+b;
        }else{
            location.href=`gradeinit`
        }
    });

    $("input.blue,input.yellow").blur(function(){
        n = $(this).parents("tr").index();
        num = $("#table1").find("tr:eq(" + (n + 1) + ")").find("td:eq(1)").text();
        name = $("#table1").find("tr:eq(" + (n + 1) + ")").find("input:eq(1)").val();
        sex = $("#table1").find("tr:eq(" + (n + 1) + ")").find("input:eq(2)").val();
        birthday = $("#table1").find("tr:eq(" + (n + 1) + ")").find("input:eq(3)").val();
        Email = $("#table1").find("tr:eq(" + (n + 1) + ")").find("input:eq(4)").val();
        remark = $("#table1").find("tr:eq(" + (n + 1) + ")").find("input:eq(5)").val();

        //alert(num+name+sex+birthday+Email+remark);

        location.href=`motifygrade?num=`+num+`&name=`+name+`&sex=`+sex+`&birthday=`+birthday+`&Email=`+Email+`&remark=`+remark;
    });

    $('#next').click(function() {
        location.href=`gradeinit?start=`+<%=(i+1)%>;
    });
    $('#previous').click(function() {
        location.href=`gradeinit?start=`+<%=(i-1)%>;
    });

    $("button[name='page']").click(function() {
        n = $(this).text();
        location.href=`gradeinit?start=`+(n-1);
    });

</script>
<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>

</body>
</html>